const Router = require('koa-router');
const path = require('path');
const common = require('../../libs/common');

let router = new Router();

const fields = [
  { title: '标题', name: 'title', type: 'text' },
  { title: '类目', name: 'catalog_ID', type: 'select'/*, ?*/ },
  { title: '时间', name: 'created_time', type: 'date' },
  { title: '作者', name: 'author', type: 'text' },
  { title: '浏览', name: 'view', type: 'number' },
  { title: '评论', name: 'comment', type: 'number' },
  { title: '摘要', name: 'summary', type: 'text' },
  { title: '列表图', name: 'list_img_src', type: 'file' },
  { title: 'banner图', name: 'banner_img_src', type: 'file' },
  { title: '内容', name: 'content', type: 'textarea' }
]
const table = 'article_table';
const page_type = 'article';
const page_types = {
  'banner': 'banner管理',
  'catalog': '类目管理',
  'article': '文章管理',
};

router.get('/', async ctx => {
  const { HTTP_ROOT } = ctx.config;

  let datas = await ctx.db.query(`SELECT * FROM ${table}`);
  // ctx.body = datas
  await ctx.render('admin/table', {
    HTTP_ROOT,
    datas,
    page_type,
    page_types,
    fields
  })
})

module.exports = router.routes();

